package com.zhang.controller;

import com.zhang.entity.Address;
import com.zhang.entity.User;
import com.zhang.service.AddressService;
import com.zhang.service.impl.AddressServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/address")
public class AddressController {
    AddressService as = new AddressServiceImpl();

    @RequestMapping("/showAll")
    public String showAll(HttpSession session, Model model){
        User user = (User) session.getAttribute("user");
        List<Address> addressList = as.selectAll(user.getId());
        model.addAttribute("addressList",addressList);
        return "forward:/address/my_address.jsp";
    }

    @RequestMapping("/addAddress")
    public String addAddress(Address address){
        as.insert(address);
        return "forward:/address/showAll.do";
    }

    @RequestMapping("/updateDelStatus")
    public String updateDelStatus(int id){
        as.updateDelStatus(id);
        return "redirect:/address/showAll.do";
    }

    @RequestMapping("/updateSelStatus")
    public String updateSelStatus(int id){
        as.updateSelStatus(id);
        return "redirect:/address/showAll.do";
    }
}
